<?php


namespace app\common\model\mysql;


use think\Exception;
use think\Model;

class User extends Model
{
    public function getAdminUserByPhone($phone)
    {
        if (empty($phone)) {
            return false;
        }

        return $this->where(['phone_number' => $phone])->find();
    }


    public function updateById($id, $data)
    {
        $id = intval($id);

        if (empty($id) || empty($data) || !is_array($data)) {
            return false;
        }

        return $this->where($id)->save($data);
    }

    public function getUserById($id)
    {
        $id = intval($id);
        if (!$id) {
            return false;
        }

        return $this->find($id);
    }

    public function getUserByUsername($username)
    {
        $user = $this->where(['username' => $username])->find();
        if (!$user) {
            return false;
        }

        return $user;
    }

}